﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Eoffice.Models;

namespace Eoffice.Controllers
{
    public class GuiController : Controller
    {
        private EofficeDb db = new EofficeDb();

        //
        // GET: /Gui/

        public ActionResult Index()
        {
            var gui_di = db.GUI_DI.Include(g => g.CQNGOAI).Include(g => g.CVDI);
            return View(gui_di.ToList());
        }

        //
        // GET: /Gui/Details/5

        public ActionResult Details(int id = 0)
        {
            GUI_DI gui_di = db.GUI_DI.Find(id);
            if (gui_di == null)
            {
                return HttpNotFound();
            }
            return View(gui_di);
        }

        //
        // GET: /Gui/Create

        public ActionResult Create()
        {
            ViewBag.MACQ = new SelectList(db.CQNGOAIs, "MACQ", "TENCQ");
            ViewBag.SOCVDI = new SelectList(db.CVDIs, "SOCVDI", "SOCVDI");
            return View();
        }

        //
        // POST: /Gui/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(GUI_DI gui_di)
        {
            if (ModelState.IsValid)
            {
                db.GUI_DI.Add(gui_di);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.MACQ = new SelectList(db.CQNGOAIs, "MACQ", "TENCQ", gui_di.MACQ);
            ViewBag.SOCVDI = new SelectList(db.CVDIs, "SOCVDI", "SOCVDI", gui_di.SOCVDI);
            return View(gui_di);
        }

        //
        // GET: /Gui/Edit/5

        public ActionResult Edit(int id = 0)
        {
            GUI_DI gui_di = db.GUI_DI.Find(id);
            if (gui_di == null)
            {
                return HttpNotFound();
            }
            ViewBag.MACQ = new SelectList(db.CQNGOAIs, "MACQ", "TENCQ", gui_di.MACQ);
            ViewBag.SOCVDI = new SelectList(db.CVDIs, "SOCVDI", "SOCVDI", gui_di.SOCVDI);
            return View(gui_di);
        }

        //
        // POST: /Gui/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(GUI_DI gui_di)
        {
            if (ModelState.IsValid)
            {
                db.Entry(gui_di).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.MACQ = new SelectList(db.CQNGOAIs, "MACQ", "TENCQ", gui_di.MACQ);
            ViewBag.SOCVDI = new SelectList(db.CVDIs, "SOCVDI", "SOCVDI", gui_di.SOCVDI);
            return View(gui_di);
        }

        //
        // GET: /Gui/Delete/5

        public ActionResult Delete(int id = 0)
        {
            GUI_DI gui_di = db.GUI_DI.Find(id);
            if (gui_di == null)
            {
                return HttpNotFound();
            }
            return View(gui_di);
        }

        //
        // POST: /Gui/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            GUI_DI gui_di = db.GUI_DI.Find(id);
            db.GUI_DI.Remove(gui_di);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}